{% extends "base/front.html" %}

{% block title %}{{ data['title'] }}{% endblock %}

{% block head %}
    <style type="text/css">
        fieldset{padding:.35em .625em .75em;margin:0 2px;border:1px solid #009;border-radius:5px;}
        legend{padding:.5em;border:0;width:auto}
        img{max-width: 100%}
        .funcarea{ padding:.35em .625em .75em;margin:0 2px;border:1px solid #009;border-radius:5px; height: auto; }
        blockquote {
            display: block;
            border-left: 8px solid #d0e5f2;
            padding: 5px 10px;
            margin: 10px 0;
            line-height: 1.4;
            font-size: 100%;
            background-color: #f1f1f1;
        }
    </style>
    {{ emit_tep('blog_show_header') }}
{% endblock %}

{% block PathNavigation %}
			<ul class="breadcrumb">
				<li>
					<a href="{{ url_for('front.index') }}">首页</a>
				</li>
                <li>
                    <a href="{{ url_for('front.blogResource', resource_type='catalog', resource_data=data.catalog) }}" title="查看 {{ data.catalog }} 分类中所有文章">{{ data.catalog }}</a>
                </li>
				<li class="active">
					{{ data.title }}
				</li>
			</ul>
{% endblock %}

{% block container %}
            <!-- 文章详情 -->
            <article>
                <header>
                    <h3 class="text-center text-success">{{ data['title'] }}
                    {% if data.get("sources") == "原创" %}
                        <attr title="原创文章"><img src="{{ url_for('static', filename='img/Original.gif') }}"></attr>
                    {% elif data.get("sources") == "转载" %}
                        <attr title="转载文章"><img src="{{ url_for('static', filename='img/Reprint.gif') }}"></attr>
                    {% elif data.get("sources") == "翻译" %}
                        <attr title="翻译文章"><img src="{{ url_for('static', filename='img/Translate.gif') }}"></attr>
                    {% endif %}
                    </h3>
                </header>
                <div class="funcarea">
                    {% set admins = g.api.user_get_admins().data %}
                    <div>
                        <a href="{{ url_for('front.blogEnjoy', bid=blogId) }}" style='color:blue' target="_blank"><button type="button" class="btn btn-success">纯享阅读</button></a>
                        {% if g.signin and g.username == data.author or g.username in admins %}
                            <a href="{{ url_for('front.blogEdit', blogId=blogId) }}" style='color:blue'><button type="button" class="btn btn-warning">编辑文章</button></a>
                            <!--TODO: fix bug-->
                            <a href="javascript:delBlog()" style='color:blue'><button type="button" class="btn btn-danger">删除文章</button></a>
                        {% endif %}
                        {% if g.username in admins %}
                            {% if data.top in ('true', 'True', True) %}
                                <a href="javascript:setTop(false)" style='color:blue'><button type="button" class="btn btn-primary">取消置顶</button></a>
                            {% else %}
                                <a href="javascript:setTop(true)" style='color:blue'><button type="button" class="btn btn-primary">置顶文章</button></a>
                            {% endif %}
                            {% if data.recommend in ('true', 'True', True) %}
                                <a href="javascript:setRecommend(false)" style='color:blue'><button type="button" class="btn btn-info">取消推荐</button></a>
                            {% else %}
                                <a href="javascript:setRecommend(true)" style='color:blue'><button type="button" class="btn btn-info">推荐文章</button></a>
                            {% endif %}
                        {% endif %}
                    </div>
                    <h6>
                        {#
                        <i class="saintic-icon saintic-icon-user saintic-icon-1"></i><a href="{{ url_for('front.userGo', uid=data.author) }}" title="由 {{ data.author }} 发布" style="color: #999">&nbsp;{{ data.author }}</a>&nbsp;
                        #}

                        {% if data.catalog %}
                        <i class="saintic-icon saintic-icon-catalog saintic-icon-1"></i><a href="{{ url_for('front.blogResource', resource_type='catalog', resource_data=data.catalog) }}" title="查看 {{ data.catalog }} 分类中所有文章" style="color: #999">&nbsp;{{ data.catalog }}</a>&nbsp;
                        {% endif %}

                        {% if data.tag %}
                        <i class="saintic-icon saintic-icon-tags saintic-icon-1"></i>
                        {% for tag in data.tag.split() %}
                            <a href="{{ url_for('front.blogResource', resource_type='tag', resource_data=tag) }}" title="查看 {{ tag }} 标签中所有文章" style="color: #999">{{ tag }}</a>&nbsp;
                        {% endfor %}
                        {% endif %}

                        {% if data.update_time or data.create_time %}
                        {% set timetext = '修改时间' if data.update_time else '创建时间' %}
                        <i class="saintic-icon saintic-icon-time saintic-icon-1"></i><scan style="color: #999" title="{{ timetext }}">&nbsp;{{ data.update_time or data.create_time }}</scan>&nbsp;
                        {% endif %}

                        {{ emit_tep('blog_show_funcarea') }}
                    </h6>
                    <hr>
                    {{ data['content'] | safe }}
                </div>
                {%- if data.get("sources") == "原创" %}
                <p></p>
                <div class="alert alert-success alert-dismissible" role="alert">
                    <b>版权声明</b>：<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;本文为原创文章，由 {{ g.config.about_awi }} 创作和发表，遵循<a href="https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh" target="_blank">CC BY-NC-ND 4.0</a>许可！<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;本文标题是：{{ data['title'] }}， 本文来源地址：<a href="{{ request.base_url }}" class="alert-link">{{ request.base_url }}</a>
                </div>
                {% endif -%}
            </article>
            <p></p>
            {{ emit_tep('blog_show_content') }}
            {{ emit_tep('valine_content') }}
            {{ emit_tep('isso_content', title=data.title) }}

{% endblock %}

{% block asideAd %}
<div class="col-md-12 column" id="ad"></div>
{% endblock %}

{% block script %}
{{ emit_tep('blog_show_script') }}
{{ emit_tep('valine_script') }}
{{ emit_tep('isso_script') }}

{% if g.config.adsense_enable in ('true', True, "True") %}
{% set ad_client, ad_slot = g.config.adsense_cleint_slot.split(",") %}
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
    //ad
    function load_google_ad(){
        $("#ad").append("<ins class='adsbygoogle' style='display:block' data-ad-client='ca-pub-{{ ad_client }}' data-ad-slot='{{ ad_slot }}' data-ad-format='auto' data-full-width-responsive='true'></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script>");
    }
    $(document).ready(function(){
        setTimeout("load_google_ad()", 3000);
    });
</script>
{% endif %}

<script type="text/javascript">
{% if g.username in g.api.user_get_admins().data %}
// 设置或取消置顶文章
function setTop(value) {
    $.ajax({
        url: "{{ url_for('api.misc') }}?action=top&blogId={{ blogId }}&value=" + value,
        method: 'POST',
        datatype: 'json',
        success: function(res) {
            console.log(res);
            if (res.success==true) {
                if(value==false) {
                    layer.msg("取消置顶成功！");
                } else {
                    layer.msg("置顶文章成功！");
                }
            } else {
                if(value==false) {
                    layer.msg("取消置顶失败！"+res.msg, {icon: 2, time: 15*1000});
                } else {
                    layer.msg("置顶文章失败！"+res.msg, {icon: 2, time: 15*1000});
                }
            }
            document.location.reload()
        },
        error: function(error){
            console.log(error);
        }
    });
}

// 设置或取消推荐文章
function setRecommend(value) {
    $.ajax({
        url: "{{ url_for('api.misc') }}?action=recommend&blogId={{ blogId }}&value=" + value,
        method: 'POST',
        datatype: 'json',
        success: function(res) {
            console.log(res);
            if (res.success==true) {
                if(value==false) {
                    layer.msg("取消推荐成功！");
                } else {
                    layer.msg("推荐文章成功！");
                }
            } else {
                if(value==false) {
                    layer.msg("取消推荐失败！"+res.msg, {icon: 2, time: 15*1000});
                } else {
                    layer.msg("推荐文章失败！"+res.msg, {icon: 2, time: 15*1000});
                }
            }
            document.location.reload()
        },
        error: function(error){
            console.log(error);
        }
    });
}

// 删除文章
function delBlog() {
    layer.confirm('你确定要删除此文章?', {
        btn: ['确认删除','我再想想']
    }, function(){
        console.warn("将要删除节点"+"{{ blogId }}");
        $.ajax({
            url: "{{ url_for('api.blog', blogId=blogId) }}",
            method: 'DELETE',
            async: false,
            datatype: 'json',
            success: function(res) {
                console.log(res);
                if (res.success==true) {
                    layer.msg("删除文章成功！", {icon: 1, time: 3*1000});
                    window.location.href="{{ url_for('front.index') }}";
                } else {
                    layer.msg("删除文章失败！"+res.msg, {icon: 2, time: 15*1000});
                }
            },
            error: function(error){
                console.log(error);
                layer.alert(res.statusText);
            }
        });
    }, function() {
        console.log("canel delete blog");
    });
}
{% endif %}
</script>
{% endblock %}
